import * as nodeHttps from "https";
import * as nodeFileSys from "fs";
import * as nodePath from "path";
import base64 from "base-64";
import {GFW_LIST_TEXT} from "./var";

const serveRequest = nodeHttps.request(GFW_LIST_TEXT, (res) => {
   let data: string = "";
   res.setEncoding("utf8");
   res.on("data", chunk => data+=chunk);
   res.on("error", err => console.error(err));
   res.on("end", () => {
       nodeFileSys.promises.writeFile(nodePath.join(__dirname, "../surge-rule/gfw-list.txt"), base64.decode(data),"utf8");
   });
});

serveRequest.end();
